extends /templates/base-flat

block page_nav
  include ./teacher-dashboard-nav

block content
  if me.isAnonymous() || (!me.isTeacher() && !view.classrooms.size())
    .container(dir="auto")
      .access-restricted.container.text-center.m-y-3
        h5(data-i18n='teacher.access_restricted')
        p(data-i18n='teacher.teacher_account_required')
        if me.isAnonymous()
          .login-button.btn.btn-lg.btn-primary(data-i18n='login.log_in')
          a.btn.btn-lg.btn-primary-alt(href="/teachers/signup" data-i18n='teacher.create_teacher_account')
        else
          a.btn.btn-lg.btn-primary(href="/teachers/update-account" data-i18n="teachers_quote.convert_account_title")
          button#logout-button.btn.btn-lg.btn-primary-alt(data-i18n="login.log_out")

      .container
        .teacher-account-blurb.text-center.col-xs-6.col-xs-offset-3.m-y-3
          h5(data-i18n='teacher.what_is_a_teacher_account')
          p(data-i18n='teacher.teacher_account_explanation')

  else if !me.canManageLicensesViaUI()
    .alert.alert-danger.text-center
      .container
        h3 You cannot access this page.
        p
          | Your APIClient does not have the necessary permissions to access this page.

  else
    if !me.isTeacher() && !me.isAdmin()
      .alert.alert-danger.text-center
        .container
          //- DNT: Temporary
          h3 ATTENTION: Please upgrade your account to a Teacher Account.
          p
            | We are transitioning to a new improved classroom management system for instructors.
            | Please convert your account to ensure you retain access to your classrooms.
          a.btn.btn-primary.btn-lg(href="/teachers/update-account") Upgrade to teacher account

    if view.state.get('shouldUpsell') || view.state.get('shouldUpsellParent')
      .bg-forest
        .container(dir="auto")
          .row
            .col-xs-9.m-t-1
              b
                if view.state.get('shouldUpsellParent')
                  span(data-i18n="payments.homeschooling")
                else
                  span(data-i18n="payments.student_licenses")
              .small-details
                i(data-i18n="payments.purchase_licenses")
            .col-xs-3
              if view.state.get('shouldUpsellParent')
                a.btn.btn-lg.btn-forest-alt.m-t-2.m-b-2(href="/payments/homeschool-coco", target="_blank")
                  b(data-i18n="general.learn_more")
              else
                a.btn.btn-lg.btn-forest-alt.m-t-2.m-b-2(href="/payments/student-licenses-small-classroom-coco", target="_blank")
                  b(data-i18n="general.learn_more")

    .container.m-t-5(dir="auto")
      h3(data-i18n='teacher.enrollments')
      h4#enrollments-blurb(data-i18n="teacher.enrollments_blurb")
      - var available = view.state.get('prepaidGroups').available
      - var pending = view.state.get('prepaidGroups').pending
      - var empty = view.state.get('prepaidGroups').empty
      - var anyPrepaids = available || pending ||  empty

      .text-center.m-t-3
        a#how-to-enroll-link(data-i18n="teacher.how_to_apply_licenses")

      .row.m-t-3
        if anyPrepaids
          #prepaids-col.col-md-8.rtl-allowed
            if _.size(available) > 0
              h5.m-b-1(data-i18n="teacher.available_credits")
              .row
                for prepaid in available
                  .prepaid-card-container.col-sm-4.col-xs-6.rtl-allowed
                    +prepaidCard(prepaid)

            if _.size(pending) > 0
              h5.m-b-1.m-t-3(data-i18n="teacher.pending_credits")
              .row
                for prepaid in pending
                  .prepaid-card-container.col-sm-4.col-xs-6.rtl-allowed
                    +prepaidCard(prepaid, 'pending-prepaid-card')

            if _.size(empty) > 0
              h5.m-b-1(data-i18n="teacher.empty_credits")
              .row
                for prepaid in empty
                  .prepaid-card-container.col-sm-4.col-xs-6.rtl-allowed
                    +prepaidCard(prepaid, 'empty-prepaid-card')

          #actions-col.col-md-4
            +addCredits

        else
          // no prepaids
          .col-sm-6.col-sm-offset-3.col-lg-4.col-lg-offset-4
            +addCredits

mixin prepaidCard(prepaid, className)
  .prepaid-card.bg-navy.text-center.p-a-2.rtl-allowed(class=className)
    h1.m-t-2.m-b-0= prepaid.openSpots()
    - var includedCourseIDs = prepaid.get('includedCourseIDs') || []
    - var credit = prepaid.get('properties') == null ? null : prepaid.get('properties').creditDetails
    - var hackstackLicense = credit && includedCourseIDs.length == 1 && includedCourseIDs[0] == view.utils.courseIDs.HACKSTACK
    if prepaid.get('type') === 'starter_license'
      div.rtl-allowed(data-i18n="teacher.starter_licenses")
    else if hackstackLicense
      div.rtl-allowed(data-i18n="teacher.hackstack_license")
    else if includedCourseIDs.length
      div.rtl-allowed(data-i18n="teacher.customized_license")
    else
      div.rtl-allowed(data-i18n="teacher.full_license")
    div.includedCourses
      if hackstackLicense
        i.course-acronym
          = translate('teacher.hackstack_credits', credit)
      else
        each id in includedCourseIDs
          i.course-acronym=view.utils.courseAcronyms[id]
    div.m-t-1.rtl-allowed(dir="auto")
      i.small-details
        if prepaid.usedSpots() === 1
          = translate('teacher.one_license_used', {totalLicenses:prepaid.totalSpots()})
        else
          = translate('teacher.num_licenses_used', {numLicensesUsed: prepaid.usedSpots(),totalLicenses:prepaid.totalSpots()})
    hr
    i.small-details
      .pull-left(data-i18n="teacher.start_date")
      .pull-right= moment(prepaid.get('startDate')).format('ll')
      .clearfix

      .pull-left(data-i18n="teacher.end_date")
      .pull-right= moment(prepaid.get('endDate')).format('ll')
      .clearfix
  if prepaid.get('type') === 'course'
    .share-details.small-details.m-b-2
      if prepaid.get('creator') === me.id
        a.share-licenses-link(data-prepaid-id=prepaid.id)
          span(data-i18n="share_licenses.share_licenses")
        a.license-stats(data-prepaid-id=prepaid.id)
          span(data-i18n="teacher.license_stats")
      else if !prepaid.creator.loading
        .shared_by
          span(data-i18n="share_licenses.shared_by")
          = " "
          a(href="mailto:" + prepaid.creator.get('email'))
            span= prepaid.creator.broadName()

mixin addCredits
  .text-center.m-b-3.m-t-3
    h5(data-i18n="courses.get_enrollments")
    if view.enrollmentRequestSent
      #enrollment-request-sent-blurb.small
        p(data-i18n="teacher.enroll_request_sent_blurb1")
        p(data-i18n="teacher.enroll_request_sent_blurb2")
        p(data-i18n="[html]teacher.enroll_request_sent_blurb3")
      button#request-sent-btn.btn-lg.btn.btn-forest(disabled=true, data-i18n="teacher.request_sent")
    else
      p.m-y-2(data-i18n="teacher.get_enrollments_blurb")
      if me.showChinaResourceInfo()
        - var {COCO_CHINA_CONST} = require('core/constants')
        p 联系我们
        p= "邮件："+COCO_CHINA_CONST.CONTACT_EMAIL
        p= "电话："+COCO_CHINA_CONST.CONTACT_PHONE
      else
        button#contact-us-btn.btn-lg.btn.btn-forest(data-i18n="contribute.contact_us_url")
        br
        p.m-y-2
          span(data-i18n="teacher.see_also_our")
          span= ' '
          a(data-i18n="nav.funding_resources_guide", href="https://www.ozaria.com/funding", target="_blank")
          span= ' '
          span(data-i18n="teacher.for_more_funding_resources")

  - var uniqueStudentsPerYear = view.state.get('uniqueStudentsPerYear')
    if _.size(uniqueStudentsPerYear) > 0
      h5.text-center(data-toggle="tooltip" title=view.getEnrollmentExplanation())
        span(data-i18n="teacher.student_enrollment_history")
        =' '
        span.glyphicon.glyphicon-question-sign
      p.m-y-2.unique-students
        each year in Object.keys(uniqueStudentsPerYear).sort().reverse()
          | !{year}: #{uniqueStudentsPerYear[year].size} #{$.i18n.t('courses.students').toLowerCase()}
          br
